<template>
	<view class="OuterBg">
		<view class="OuterBox">
			<view class="OuterTemplate">
				<view class="exam_line u-flex-between">
					<view class="shead_tit  irequired">
						名称
					</view>
					<view class="input_Arae">
						<input type="text" placeholder="请输入名称" v-model.trim="role_name" maxlength="8">
					</view>
				</view>
				<view class="exam_line u-flex-between">
					<view class="shead_tit  irequired">
						选择员工
					</view>
					<MultipleSelect :selectList="empList" :selectData="selectData" @change="multipleChange"></MultipleSelect>
				</view>
			</view>
			
			<!-- <view class="OuterTemplate auth_box">
				<Permissionset ref="ref_perm" :auth_list="auth_list" :auth_ids="auth_ids" childkey="notLower"
					authkey="id" @saveauth="saveclick"></Permissionset>
			</view> -->
			<!--  -->
			<view class="step_area step_Audit" style="padding: 10px;">
					<view class="step_btn FlexRow  style2"style="background-color: #fd7400;
			color: #fff;
			height: 50px;
			font-size: 16px;
			border-radius: 4rpx;
			line-height: 50px;
			    text-align: center;"  @click="addEmp">
						保存
					</view>
				</view>
		</view>

	</view>
</template>

<script>
	import MultipleSelect from '../../pages/components/select/MultipleSelect.vue.vue';
	export default {
		components: {
			MultipleSelect
		},
		data() {
			return {
				lookUp: false,
				editUp: false,
				ctitle: '添加角色',
				// 
				role_name: '',
				role_desc: '',
				c_id: '',
				// 初始权限菜单
				auth_list: [],
				custAccId:'',
				// 已勾选的权限
				auth_ids: '',
				selectList: [
					{
						label: '选择1a',
						value: '1'
					},
					{
						label: '选择2as',
						value: '2'
					},
					{
						label: '选择3',
						value: '3'
					},
					{
						label: '选择4',
						value: '4'
					},
					{
						label: '选择5asd',
						value: '5'
					},
					{
						label: '选择6',
						value: '6'
					},
					{
						label: '选择7',
						value: '7'
					},
					{
						label: '选择8',
						value: '8'
					},
					{
						label: '选择9',
						value: '9'
					},
				],
				selectData: ['1', '3', '5', '8'],
				empList:[],
				acId:'',
				addAcIds:''
			}
		},
		onLoad(){
			this.getEmpList()
			this.custAccId = uni.getStorageSync('custAccid')
			this.acId = uni.getStorageSync('acId')
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getPullRefresh()
		},
		methods: {
			// 下拉刷新请求数据
			getPullRefresh(){
				console.clear()
				console.log('onPullDownRefresh')
				
				this.getEmpList()
				
			},
			// 批量操作
			multipleChange(val, idx) {
				console.log('选中', val, idx)
				this.addAcIds = val
				console.log(this.addAcIds)
				let obj={}
				for(let i in this.addAcIds){
					obj[i]=this.addAcIds[i]
				}
				console.log(obj,'obj')
				let newObj = Object.keys(obj).map(val => ({
				        acId: obj[val],
				 }));
				 this.addAcIds=newObj
				 console.log(newObj,'newObj')
			},
		
		// 获取员工数据
		async getEmpList() {
			const res = await uni.$api.authority.getEmpList({
				custAccId: this.custAccId
			})
			this.empList = res.data.map(i => {
				return {
					label: i.empName,
					value: i.id,
					...i
				}
			})
			uni.stopPullDownRefresh()
		},
			// 新增角色
			async addEmp(){
				let zjEmpRole = {
					custAccId: this.custAccId,
					roName: '',
				}
				zjEmpRole.roName=this.role_name
				let data = {
					zjEmpRole: zjEmpRole,
					zjEmp:this.addAcIds
				}
				const res = await uni.$api.authority.addEmp(this.acId,data)
				console.log(res)
				if(res.code===0){
					uni.showToast({
						title:'新增成功'
					})
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pagesA/pages/authority/authority'
						})
					},2000)
				}
			}
		},
	}
</script>
<style lang="scss" scoped>
	@import "./css/role.scss";
</style>